#生成器

'''
每次调用__next__()方法时，count函数会运行到语句yield n处为止，__next__()的返回值就是生成值n，再次调用__next__()方法时，函数继续执行yield之后的语句
'''

def counter(start =0):
    count = start
    while True:
        print('before')
        val = (yield count)
        print('after')
        if val is not None:
            count =val
        else:
            count +=1

# count = counter(5)
# print(count.__next__())
# print(count.__next__())
# print(count.send(10))
# print(count.__next__())